import {defineConfig} from 'vite'
import vue from '@vitejs/plugin-vue'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import {ElementPlusResolver} from 'unplugin-vue-components/resolvers'
import {getBabelOutputPlugin} from "@rollup/plugin-babel";
/**
 * 引入路径
 */
import path from 'path'

const pathSrc = path.resolve(__dirname, 'src')

export default defineConfig({
    runtimeCompiler: true,
    resolve: {
        alias: {
            '@/': `${pathSrc}/`,
        },
    },
    plugins: [
        vue(),
        AutoImport({
            resolvers: [ElementPlusResolver()],
        }),
        Components({
            resolvers: [ElementPlusResolver()],
        }),
        // /**
        //  * 安装"@babel/plugin-proposal-nullish-coalescing-operator": "^7.18.6",//空值合并 ??
        //  *     "@babel/plugin-proposal-optional-chaining": "^7.18.9", //可选链 ?.
        //  *  plugins里面配置   "@babel/plugin-proposal-optional-chaining"
        //  */
        // {
        //     "plugins": [
        //         "@babel/plugin-proposal-nullish-coalescing-operator",
        //         "@babel/plugin-proposal-optional-chaining"
        //     ]
        // }
    ],
    css: {
        preprocessorOptions: {
            scss: {
                // '@import "assets/scss/globalVar.scss";@import "assets/scss/globalMixin.scss";'
                // additionalData: '@import "../assets/scss/globalVar.scss";@import "../assets/scss/globalMixin.scss";'
                // additionalData: `@use "~/styles/element/index.scss" as *;`,
            }
        }
    },
    build: {
        rollupOptions: {
            plugins: [
                getBabelOutputPlugin({
                    configFile: path.resolve(__dirname, './babel.config.js'),
                }),
            ],
        },
    },
})
